<?php
/**
 * @name commentopen.php
 * @date 2015-07-29
 * @author:yuebin
 */
namespace haibao\comment\business;
use \haibao\comment\model\data\CommentType as CommentTypeModel;
class CommentOpen extends \haibao\cms\business\Base{
	
	public static function addCommentOpenByComment($commentModel){
		
		if(count($commentModel->ThirdPushType) == 0) return;
		$commenOpenModels = self::packageModel($commentModel);
		$data = new \haibao\comment\data\CommentOpen();
		$data->addAll($commenOpenModels);
	}
	
	private static function packageModel($commentModel){

		$pushContent = $fullTextUrl = '';
		switch ($commentModel->CommentsTypeCode ){
		case CommentTypeModel::TYPE_CODE_ARTICLE:
			$data = new \haibao\cms\data\Article();
			$articleInfo = $data->getOneById($commentModel->ObjectId);
			$pushContent = $commentModel->MyComment.'【@海报时尚网 】'.$articleInfo->Title." 全文→ ".\haibao\classlibrary\comment\Config::getConfig(\haibao\classlibrary\comment\Config::CLASSLIBRARY_CONFIG_HAIBAO_URL).'/article/'.$articleInfo->PublishId.'.html';
			break;
		case CommentTypeModel::TYPE_CODE_PIC:
			$data = new \haibao\cms\data\imagecollective\ImageCollective();
			$picInfo = $data->getOneById($commentModel->ObjectId);
			$pushContent = $commentModel->MyComment.'【@海报时尚网 】'.$picInfo->Title." 全文→ ".\haibao\classlibrary\comment\Config::getConfig(\haibao\classlibrary\comment\Config::CLASSLIBRARY_CONFIG_HOST_PIC).'/pics/'.$picInfo->Id.'.htm';
			break;
		case CommentTypeModel::TYPE_CODE_VIDEO:
			$data = new \haibao\cms\data\Video();
			$videoInfo = $data->getOneById($commentModel->ObjectId);
			$pushContent = $commentModel->MyComment.'【@海报时尚网 】'.$videoInfo->Title." 全文→ ".\haibao\classlibrary\comment\Config::getConfig(\haibao\classlibrary\comment\Config::CLASSLIBRARY_CONFIG_HOST_EXCLUSIVE).'/play/'.$videoInfo->Id.'.htm';
			break;
		case CommentTypeModel::TYPE_CODE_FEATURE:
			$data = new \haibao\cms\data\FeaturePublish();
			$featureInfo = $data->getOneById($commentModel->ObjectId);
			$pushContent = $commentModel->MyComment.'【@海报时尚网 】'.$featureInfo->FeatureTitle." 全文→ ".$featureInfo->Url;
			break;
		default :
			break;
		}
		
		$pushContent = preg_replace('/<img.*src="(.*)".*?>/i', "$1", $pushContent);
		$models = array();
		foreach($commentModel->ThirdPushType as $type){
			$commentOpenModel = new \haibao\comment\model\data\CommentOpen();
			$commentOpenModel->Content = $pushContent;
			$commentOpenModel->UserId = $commentModel->UserId;
			$commentOpenModel->OpenStatus = \haibao\comment\model\data\CommentOpen::OPEN_STATUS_ZERO;
			$commentOpenModel->OpenType = $type;
			$commentOpenModel->CreateTime = new \DateTime();
			array_push($models,$commentOpenModel);
		}
		return $models;
		
	}
	
	private static function regCommentImg(){
		
	}
}